package VUTHANHPHUC.HOMEWORK.JSON;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.map.ObjectMapper;

import PHANVANVUONG.JSON.HOMEWORK.Student;

public class Ex01 {
	public static void main(String[] args) {
		Student stu01=new Student("SV001", "Nguyễn Văn A", 8.5);
		Student stu02=new Student("SV002", "Trần Thị B", 9.0);
		
		List<Student> list=new ArrayList<Student>();
		list.add(stu01);
		list.add(stu02);
		
		try{
			ClassLoader objcls= (Thread.currentThread()).getContextClassLoader();
			URL url= objcls.getResource("VUTHANHPHUC/HOMEWORK/JSON/");
			
			ObjectMapper objMap=new ObjectMapper();
			objMap.writeValue(new File(url.getPath().toString()+"Student.json"), list);
			System.out.println("Ghi file thành công!");
		}catch(Exception e){
			System.out.println("Error: "+e.toString());
		}
	}
}
